function map(array: any[], mapFunc: any) {
  return (array || []).map(mapFunc);
}

var colorNames: any = {
  aliceblue: "#f0f8ff",
  antiquewhite: "#faebd7",
  aqua: "#00ffff",
  aquamarine: "#7fffd4",
  azure: "#f0ffff",
  beige: "#f5f5dc",
  bisque: "#ffe4c4",
  black: "#000000",
  blanchedalmond: "#ffebcd",
  blue: "#0000ff",
  blueviolet: "#8a2be2",
  brown: "#a52a2a",
  burlywood: "#deb887",
  cadetblue: "#5f9ea0",
  chartreuse: "#7fff00",
  chocolate: "#d2691e",
  coral: "#ff7f50",
  cornflowerblue: "#6495ed",
  cornsilk: "#fff8dc",
  crimson: "#dc143c",
  cyan: "#00ffff",
  darkblue: "#00008b",
  darkcyan: "#008b8b",
  darkgoldenrod: "#b8860b",
  darkgray: "#a9a9a9",
  darkgreen: "#006400",
  darkkhaki: "#bdb76b",
  darkmagenta: "#8b008b",
  darkolivegreen: "#556b2f",
  darkorange: "#ff8c00",
  darkorchid: "#9932cc",
  darkred: "#8b0000",
  darksalmon: "#e9967a",
  darkseagreen: "#8fbc8f",
  darkslateblue: "#483d8b",
  darkslategray: "#2f4f4f",
  darkturquoise: "#00ced1",
  darkviolet: "#9400d3",
  deeppink: "#ff1493",
  deepskyblue: "#00bfff",
  dimgray: "#696969",
  dodgerblue: "#1e90ff",
  firebrick: "#b22222",
  floralwhite: "#fffaf0",
  forestgreen: "#228b22",
  fuchsia: "#ff00ff",
  gainsboro: "#dcdcdc",
  ghostwhite: "#f8f8ff",
  gold: "#ffd700",
  goldenrod: "#daa520",
  gray: "#808080",
  green: "#008000",
  greenyellow: "#adff2f",
  honeydew: "#f0fff0",
  hotpink: "#ff69b4",
  indianred: "#cd5c5c",
  indigo: "#4b0082",
  ivory: "#fffff0",
  khaki: "#f0e68c",
  lavender: "#e6e6fa",
  lavenderblush: "#fff0f5",
  lawngreen: "#7cfc00",
  lemonchiffon: "#fffacd",
  lightblue: "#add8e6",
  lightcoral: "#f08080",
  lightcyan: "#e0ffff",
  lightgoldenrodyellow: "#fafad2",
  lightgrey: "#d3d3d3",
  lightgreen: "#90ee90",
  lightpink: "#ffb6c1",
  lightsalmon: "#ffa07a",
  lightseagreen: "#20b2aa",
  lightskyblue: "#87cefa",
  lightslategray: "#778899",
  lightsteelblue: "#b0c4de",
  lightyellow: "#ffffe0",
  lime: "#00ff00",
  limegreen: "#32cd32",
  linen: "#faf0e6",
  magenta: "#ff00ff",
  maroon: "#800000",
  mediumaquamarine: "#66cdaa",
  mediumblue: "#0000cd",
  mediumorchid: "#ba55d3",
  mediumpurple: "#9370d8",
  mediumseagreen: "#3cb371",
  mediumslateblue: "#7b68ee",
  mediumspringgreen: "#00fa9a",
  mediumturquoise: "#48d1cc",
  mediumvioletred: "#c71585",
  midnightblue: "#191970",
  mintcream: "#f5fffa",
  mistyrose: "#ffe4e1",
  moccasin: "#ffe4b5",
  navajowhite: "#ffdead",
  navy: "#000080",
  oldlace: "#fdf5e6",
  olive: "#808000",
  olivedrab: "#6b8e23",
  orange: "#ffa500",
  orangered: "#ff4500",
  orchid: "#da70d6",
  palegoldenrod: "#eee8aa",
  palegreen: "#98fb98",
  paleturquoise: "#afeeee",
  palevioletred: "#d87093",
  papayawhip: "#ffefd5",
  peachpuff: "#ffdab9",
  peru: "#cd853f",
  pink: "#ffc0cb",
  plum: "#dda0dd",
  powderblue: "#b0e0e6",
  purple: "#800080",
  rebeccapurple: "#663399",
  red: "#ff0000",
  rosybrown: "#bc8f8f",
  royalblue: "#4169e1",
  saddlebrown: "#8b4513",
  salmon: "#fa8072",
  sandybrown: "#f4a460",
  seagreen: "#2e8b57",
  seashell: "#fff5ee",
  sienna: "#a0522d",
  silver: "#c0c0c0",
  skyblue: "#87ceeb",
  slateblue: "#6a5acd",
  slategray: "#708090",
  snow: "#fffafa",
  springgreen: "#00ff7f",
  steelblue: "#4682b4",
  tan: "#d2b48c",
  teal: "#008080",
  thistle: "#d8bfd8",
  tomato: "#ff6347",
  turquoise: "#40e0d0",
  violet: "#ee82ee",
  wheat: "#f5deb3",
  white: "#ffffff",
  whitesmoke: "#f5f5f5",
  yellow: "#ffff00",
  yellowgreen: "#9acd32"
}

  
export class Color {
  type: string;
  rgba: any[];

  constructor(t: any) {
    this.type = "AMap.Color",
    this.rgba = [],
    this.Vb(t)
  }

  static Wb(t: any) {
    return {
        rgba: t.rgba
    }
  }

  static Gb(t: any) {
      return new Color(t.rgba)
  }

  static FV(t: any, e: any) {
    var r = this.DV(t[0], t[1], t[2], t[3]);
    var n = r[0], i = r[1], t = r[2], z = r[3];
    return this.GQ(n += (.5 < n ? -.5 : .5) * e * .35, i -= (i - .5) * e * .35 * 5, t -= (t - .5) * e * .35, z)
  }

  static DV(t: any, e: any, r: any, n: any) {
      var i: number = 0, a, o, s = Math.max(t, e, r), u = Math.min(t, e, r), c = (s + u) / 2;
      if (s === u) i = a = 0;
      else {
          switch (o = s - u,
          a = .5 < c ? o / (2 - s - u) : o / (s + u),
          s) {
          case t:
              i = (e - r) / o + (e < r ? 6 : 0);
              break;
          case e:
              i = (r - t) / o + 2;
              break;
          case r:
              i = (t - e) / o + 4
          }
          i /= 6
      }
      return [i, a, c, n]
  }

  static uQ(t: number, e: number, r: number) {
      return r < 0 && (r += 1),
      1 < r && --r,
      r < 1 / 6 ? t + 6 * (e - t) * r : r < .5 ? e : r < 2 / 3 ? t + (e - t) * (2 / 3 - r) * 6 : t
  }

  static GQ(t: number, e: number, r: number, n: number) {
      var i, a, o;
      return 0 === e ? i = a = o = r : (i = this.uQ(e = 2 * r - (r = r < .5 ? r * (1 + e) : r + e - r * e), r, t + 1 / 3),
      a = this.uQ(e, r, t),
      o = this.uQ(e, r, t - 1 / 3)),
      [i, a, o, n]
  }

  static Hb(t: string, e?: any) {
      void 0 === e && (e = []);
      for (var r = 0, n = t.length; r < n; r += 2)
          e[r / 2] = parseInt(t.substr(r, 2), 16);
      return e
  }

  static Yx(t: any) {
      return t.startsWith("#") && (t = t.substr(1)),
      colorNames[t] ? Color.Hb(colorNames[t].substr(1)) : 1 === t.length ? Color.Hb(t + t + t + t + t + t) : 3 === t.length ? Color.Hb(t[0] + t[0] + t[1] + t[1] + t[2] + t[2]) : 6 === t.length ? Color.Hb(t) : [0, 0, 0]
  }

  static normalize(t: any) {
      for (var e = [], r = 0, n = t.length; r < n; r++)
          e[r] = t[r] / 255;
      return e
  }

  static create(t: any) {
      return t ? new Color(t) : null
  }

  normalize() {
      return [this.rgba[0] / 255, this.rgba[1] / 255, this.rgba[2] / 255, this.rgba[3] / 255]
  }

  Vb(t: any) {
      "string" == typeof t ? colorNames[t] ? this.Hb(colorNames[t].substr(1)) : 0 !== t.length && (1 !== (t = t.startsWith("#") ? t.substr(1) : t).length ? 3 !== t.length ? 6 !== t.length ? 8 !== t.length ? t.startsWith("rgba(") ? this.Yb(colorNames[t].substr(1)) : t.startsWith("rgb(") && this.Kb(colorNames[t].substr(1)) : this.$b(t) : this.Hb(t) : this.Hb(t[0] + t[0] + t[1] + t[1] + t[2] + t[2]) : this.Hb(t + t + t + t + t + t)) : t instanceof Array && (this.rgba[0] = t[0],
      this.rgba[1] = t[1],
      this.rgba[2] = t[2],
      this.rgba[3] = t[3] || 255)
  }

  Hb(t: string) {
      this.$b(t + "FF")
  }

  $b(t: string) {
      for (var e = 0, r = t.length; e < r; e += 2)
          this.rgba[e / 2] = parseInt(t.substr(e, 2), 16)
  }

  Kb(b: string) {
    var t = b.split(",");
      this.rgba[0] = parseInt(t[0].substr(4), 10),
      this.rgba[1] = parseInt(t[1], 10),
      this.rgba[2] = parseInt(t[2], 10),
      this.rgba[3] = 255
  }

  Yb(b: string) {
      var t = b.split(",");
      this.rgba[0] = parseInt(t[0].substr(5), 10),
      this.rgba[1] = parseInt(t[1], 10),
      this.rgba[2] = parseInt(t[2], 10),
      this.rgba[3] = 255 * parseFloat(t[3]) << 0
  }
}


export class StyleParser {
  static SZ(t: any) {
    for (var e = t.stylemaps, r = e.length, n: any = {}, i = 0; i < r; i++) {
        var a = e[i]
          , o = a.key[0]
          , s = a.key[1]
          , u = {
            browserStyle: undefined,
            levelStyleMapping: undefined,
            type: '',
            z: 0
          };
        void 0 === n[o] && (n[o] = {}),
        (n[o][s] = u).browserStyle = a.browserStyle;
        for (var c: any = {}, f = a.levelStyleMapping.length, l = 0; l < f; l += 2) {
            var h = a.levelStyleMapping[l]
              , d = a.levelStyleMapping[l + 1];
            c[h] = d
        }
        u.levelStyleMapping = c;
        var v: any = undefined;
        switch (o[0]) {
        case "1":
            v = StyleParser.Xe;
            break;
        case "2":
            v = StyleParser.rn,
            u.type = "road";
            break;
        case "3":
            v = StyleParser.cn;
            break;
        case "4":
            v = StyleParser.un;
            break;
        case "5":
            v = StyleParser.ln,
            u.type = "building"
        }
        for (var g: any = u.browserStyle, b = 0, p = g.length; b < p; b += 1) {
            var m = g[b];
            if (g[b] = v(m),
            void 0 === u.z)
                switch (o[0]) {
                case "2":
                    u.z = (g[b] ? g[b][0] : u).z;
                    break;
                case "1":
                case "3":
                case "4":
                case "5":
                    u.z = g[b].z;
                    break;
                default:
                    u.z = -1
                }
        }
        StyleParser.Sn(u)
    }
    return n
  }
  static Sn(t: any) {
    if (void 0 !== t.levelStyleMapping[3] && (t.levelStyleMapping[2] = t.levelStyleMapping[3]),
    void 0 !== t.levelStyleMapping[20] && (t.levelStyleMapping[21] = t.levelStyleMapping[20],
    t.levelStyleMapping[22] = t.levelStyleMapping[20],
    t.levelStyleMapping[23] = t.levelStyleMapping[20],
    t.levelStyleMapping[24] = t.levelStyleMapping[20],
    t.levelStyleMapping[25] = t.levelStyleMapping[20],
    t.levelStyleMapping[26] = t.levelStyleMapping[20],
    t.levelStyleMapping[27] = t.levelStyleMapping[20],
    t.levelStyleMapping[28] = t.levelStyleMapping[20],
    t.levelStyleMapping[29] = t.levelStyleMapping[20],
    t.levelStyleMapping[30] = t.levelStyleMapping[20]),
    "building" === t.type && t.levelStyleMapping && (delete t.levelStyleMapping[15],
    delete t.levelStyleMapping[16]),
    "road" === t.type && void 0 !== t.levelStyleMapping[20]) {
        var e = t.browserStyle
          , r = t.levelStyleMapping[20]
          , n = e[r];
        if (n)
            for (var i = 1; i <= 10; i++) {
                var a = [];
                a.push(Object.assign({}, n[0])),
                a.push(Object.assign({}, n[1])),
                a[0].roadWidth = a[0].roadWidth * Math.pow(2, i),
                a[0].borderWidth = a[0].borderWidth * Math.pow(2, i),
                t.browserStyle.push(a),
                t.levelStyleMapping[i + 20] = r + i
            }
    }
  }


  static Xe(t: any) {
    var e = t.split("&");
    return (t = {
      iconID: undefined
    }).iconID = e[0],
    t.fontSize = parseInt(e[1], 10),
    t.faceColor = StyleParser.Je(e[2]),
    t.borderColor = StyleParser.Je(e[3]),
    t.holoColor = StyleParser.Je(e[4]),
    t.showMode = parseInt(e[6], 10),
    t.showText = 2 === t.showMode ? 0 : 1,
    t.forceShow = parseInt(e[7], 10),
    t.clickEnable = parseInt(e[8], 10),
    t.xOffset = parseInt(e[9], 10),
    t.yOffset = parseInt(e[10], 10),
    t.iconFile = e[5],
    t
  }
  
  static rn(b: any) {
    var e = b.split("|")
      , r = e[0].split("&")
      , t: any = {};
    e[0] ? (t.roadWidth = parseInt(r[0], 10),
    t.roadColor = StyleParser.Je(r[1]),
    t.roadStyle = r[2] || "",
    t.borderWidth = parseInt(r[3], 10),
    t.borderColor = StyleParser.Je(r[4]),
    t.borderStyle = r[5] || "",
    t.z = parseInt(r[6], 10),
    t.roadStyle && t.roadStyle.indexOf && (0 === t.roadStyle.indexOf("dash") ? (t.roadDash = t.roadStyle.substring(4).slice(1, -1).split(","),
    t.roadDash = map(t.roadDash, function(t: any) {
        return parseInt(t, 10)
    }),
    2 === t.roadDash.length && (r = t.roadDash).push.apply(r, t.roadDash)) : 0 < t.roadStyle.indexOf("railway") || t.roadStyle.indexOf("dash_crewel")),
    t.borderStyle && t.borderStyle.indexOf && (0 === t.borderStyle.indexOf("dash") ? (t.borderDash = t.borderStyle.substring(4).slice(1, -1).split(","),
    t.borderDash = map(t.borderDash, function(t: any) {
        return parseInt(t, 10)
    }),
    2 === t.borderDash.length && (n = t.borderDash).push.apply(n, t.borderDash)) : 0 < t.borderStyle.indexOf("railway") || t.borderStyle.indexOf("dash_crewel"))) : (t.roadWidth = 0,
    t.roadColor = StyleParser.Je("00000000"),
    t.roadStyle = "",
    t.borderWidth = 0,
    t.borderColor = StyleParser.Je("00000000"),
    t.borderStyle = "",
    t.z = 0);
    var n: any = {};
    return e[1] && (e = e[1].split("&"),
    n.iconID = "",
    n.fontSize = parseInt(e[1], 10),
    n.faceColor = StyleParser.Je(e[2]),
    n.borderColor = StyleParser.Je(e[3]),
    n.z = parseInt(e[4], 10)),
    [t, n]
  }
  
  static ln(b: any) {
    var e = b.split("&");
    var t: any = {}
    return t.faceColor = StyleParser.Je(e[0]),
    t.borderWidth = parseInt(e[1], 10),
    t.borderColor = StyleParser.Je(e[2]),
    t.wallColor1 = StyleParser.Je(e[3]),
    t.wallColor2 = StyleParser.Je(e[4]),
    t.opacity = parseFloat(e[5]),
    t.z = parseInt(e[6], 10),
    t
  }
  
  static un(b: any) {
    var e = b.split("&");
    var t: any = {}
    return t.iconID = e[0],
    t.fontSize = parseInt(e[1], 10),
    t.faceColor = StyleParser.Je(e[2]),
    t.borderColor = StyleParser.Je(e[3]),
    t.holoColor = null,
    t.z = parseInt(e[5], 10),
    t
  }
  
  static cn(b: any) {
    var e = b.split("&");
    var t: any = {
      faceColor: undefined
    };
    return t.faceColor = StyleParser.Je(e[0]),
    t.borderWidth = 0,
    t.borderColor = null,
    t.z = parseInt(e[3], 10),
    t
  }

  static Je(t: any) {
    if (!t)
        return null;
    if (t && "0" !== t) {
        if (8 !== t.length || (t = t.slice(2) + t.slice(0, 2)),
        StyleParser.yQ && StyleParser.yQ[t])
            return Color.create(StyleParser.yQ[t]);
        var e: any = Color.create(t);
        return StyleParser.yQ || (StyleParser.yQ = {}),
        StyleParser.yQ[t] || (StyleParser.yQ[t] = e.rgba.slice(0)),
        e
    }
    return null
  }

  static yQ: any = {}
}
